#include <cstdio>
#include <vector>


/**
 * 有向图的邻接表
 * 
 */
int main() {

	std::vector<std::vector<int>> graph(6, std::vector<int>());

	int edges[6][2] = {
		//1指向2
		{1,2},
		//2指向1
		{2,1},
		//2指向3
		{2,3},
		//3指向5
		{3,5},
		//4指向5
		{4,5},
		//5指向1
		{5,1}
	};

	for (int i = 0; i < 6; i++) {
		graph[edges[i][0]].push_back(edges[i][1]);
	}

	printf("有向图的邻接表遍历:\n");

	for (int i = 0; i < graph.size(); i++) {
		printf("%d -> ", i);
		for (int j = 0; j < graph[i].size(); j++) {
			printf("%d ", graph[i][j]);
		}
		printf("\n");
	}

	return 0;

}